package com.tanhua.dubbo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.BlackList;
import com.tanhua.domain.UserInfo;
import com.tanhua.dubbo.BlackListAPI;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.vo.BlackListVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;

@DubboService
public class BlackListAPIImpl implements BlackListAPI {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public BlackListVo getBlackListByPage(Long userId, Integer page, Integer pagesize) {
        //查询组装返回结果--
        Page pages = new Page<>(page, pagesize);
        IPage<UserInfo> iPage = blackListMapper.findBlackListByUserId(pages, userId);
        BlackListVo vo = new BlackListVo();
        vo.setCounts((int)iPage.getTotal());
        vo.setPage(page);
        vo.setPagesize(pagesize);
        int ps = vo.getCounts()%vo.getPagesize()==0?vo.getCounts()/vo.getPagesize():(vo.getCounts()/vo.getPagesize()+1);
        vo.setPages(ps);
        vo.setItems(iPage.getRecords());
        return vo;
    }

    @Override
    public void deleteBlackList(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("black_user_id",blackUserId);
        blackListMapper.delete(wrapper);
    }


}
